<template lang="">
  <div>
    <el-dialog title="员工分配角色" :visible="isShowDialog" @close="closeBtn">
      <el-checkbox-group v-model="roleIds">
        <el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">
          {{ role.name }}
        </el-checkbox>
      </el-checkbox-group>
      <template #footer>
        <el-button type="primary" @click="btnOk">确认</el-button>
        <el-button type="success" @click="closeBtn">取消</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import { getRoleList } from '@/api/setting'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleList: [],
      roleIds: [],
      employeeId: ''
    }
  },
  async created() {
    const { rows } = await getRoleList({ page: 1, pageSize: 999 })
    this.roleList = rows
    console.log('角色列表', this.roleList)
  },
  methods: {
    // 数据回显
    async getRoleIds(employeeId) {
      this.employeeId = employeeId
      const { roleIds } = await getUserDetailById(employeeId)
      // 回显多选框组
      this.roleIds = roleIds
    },

    async btnOk() {
    // 发请求
      await assignRoles({ id: this.employeeId, roleIds: this.roleIds })
      // 提示用户
      this.$message.success('操作成功')
      // 关闭弹窗
      this.$emit('update:isShowDialog', false)
    },

    closeBtn() {
      // 清空数据
      this.roleList = []
      //   关闭弹窗
      this.$emit('update:isShowDialog', false)
    }

  }
}
</script>
<style lang="">

</style>
